package cn.zhang.violet.utils

import org.apache.spark.sql.Row

object RptKpi {
   def apply(str:Row)={

     // 提取个指标相关的字段
     val reqMode = str.getAs[Int]("requestmode")
     val proNode = str.getAs[Int]("processnode")
     val effTive = str.getAs[Int]("iseffective")
     val billing = str.getAs[Int]("isbilling")
     val isbid = str.getAs[Int]("isbid")
     val iswin = str.getAs[Int]("iswin")
     val adOrderId = str.getAs[Int]("adorderid")

     val rawReq = if(reqMode == 1 && proNode >= 1) 1 else 0
     val effReq = if(reqMode == 1 && proNode >= 2) 1 else 0
     val adReq =if(reqMode == 1 && proNode == 3) 1 else 0

     val adRtbReq = if(effTive == 1 && billing == 1 && isbid == 1 && adOrderId != 0) 1 else 0
     val adSuccRtbAndCostAndConsumption = if(effTive == 1 && billing == 1 && iswin == 1){

       val winPrice = str.getAs[Double]("winprice")
       val adPayment = str.getAs[Double]("adpayment")
       (1,adPayment /1000,winPrice /1000)

     } else (0,0d,0d)
     val adShow = if(reqMode == 2 && effTive == 1) 1 else 0
     val adClick = if(reqMode == 3 && effTive == 1) 1 else 0


     //组成一个对偶元祖
     List(rawReq, effReq, adReq, adRtbReq, adSuccRtbAndCostAndConsumption._1,
       adShow, adClick, adSuccRtbAndCostAndConsumption._2,
       adSuccRtbAndCostAndConsumption._3)

   }
}
